package com.hzy.yiyaoba.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.Toast;

import com.hzy.yiyaoba.utils.AppManager;
import com.hzy.yiyaoba.utils.BitmapManager;
import com.hzy.yiyaoba.utils.HttpManager;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.HttpUtils;
import com.umeng.analytics.MobclickAgent;

public abstract class BaseActivity extends FragmentActivity {
	
	protected HttpUtils mHttpUtils;
	protected BitmapUtils mBmpUtils;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		mHttpUtils = HttpManager.getInstance().getHttpUtils();
		mBmpUtils = BitmapManager.getInstance(this).getBitmapUtils();
		AppManager.getInstance().addActivity(this);
		initEnvironment();
		setContentView(getLayoutRes());
		initView();
	}

	protected abstract void initEnvironment();

	protected abstract int getLayoutRes();

	protected abstract void initView();

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onDestroy() {
		AppManager.getInstance().finishActivity(this);
		super.onDestroy();
	}

	protected static String getSimpleName(Class<?> c) {
		return c.getSimpleName();
	}

	protected void showShortToast(String info) {
		Toast.makeText(this, info, Toast.LENGTH_SHORT).show();
	}
	
	/**
	 * 俩个view是同一个则显示，否则消失
	 * 
	 * @param view1
	 * @param view2
	 */
	protected void showView(View view1, View view2) {
		setViewVisible(view2, view1.getId() == view2.getId());
	}

	/**
	 * 设置view可见性
	 * 
	 * @param v
	 * @param isShow
	 */
	protected void setViewVisible(View v, boolean isShow) {
		v.setVisibility(isShow ? View.VISIBLE : View.INVISIBLE);
	}
}
